import wx from 'weixin-js-sdk';
export default{
  install (Vue) {
    Vue.prototype.baseUrl = 'https://es.11cm.com.cn';
    Vue.prototype.wxUrl = 'https://wxapi.11cm.com.cn';
    Vue.prototype.trims = function(str) {
      return str.replace(/(^\s*)|(\s*$)/g, '');
    };
    Vue.prototype.wxShare = function(opt, url) {
      wx.config({
        debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
        appId: opt.AppID, // 必填，公众号的唯一标识
        timestamp: opt.Timestamp, // 必填，生成签名的时间戳
        nonceStr: opt.Noncestr, // 必填，生成签名的随机串
        signature: opt.Signature, // 必填，签名
        jsApiList: ['onMenuShareAppMessage', 'onMenuShareTimeline', 'chooseImage'] // 必填，需要使用的JS接口列表
      });
      wx.ready(function() {
        // 需在用户可能点击分享按钮前就先调用
        wx.onMenuShareAppMessage({
          title: opt.Theme, // 分享标题
          desc: opt.SubTheme, // 分享描述
          link: url, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
          imgUrl: opt.BusinessLogo, // 分享图标
          success: function() {
            // 设置成功
          }
        });
        wx.onMenuShareTimeline({
          title: opt.Theme, // 分享标题
          link: url, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
          imgUrl: opt.BusinessLogo, // 分享图标
          success: function() {
            // 设置成功
          }
        });
      });
    };
    Vue.prototype.buildFormJson = function(opt) {
      var list = [];
      if (opt.IsUploadPic) {
        list.push({
          type: 'upload', // 控件类型
          key: 'upload',
          value: '',
          label: '上传头像',
          must: true,
          disabled: false, // 是否禁止上传
          accept: 'image/*', // 接受的文件类型,如image/png, image/jpeg
          maxSize: 1048576 // 字节单位byte
        });
      }
      if (!opt.IsHideName) {
        list.push({
          type: 'text',
          key: 'name',
          value: '',
          label: '姓名',
          placeholder: '请输入真实姓名',
          must: true,
          readonly: false,
          disabled: false,
          maxlength: 4
        });
      }

      if (opt.IsSex) {
        list.push({
          type: 'radio',
          key: 'sex',
          value: '男',
          label: '性别',
          must: true,
          disabled: false,
          data: [{
            value: '男',
            text: '男'
          }, {
            value: '女',
            text: '女'
          }]
        });
      }
      if (!opt.IshidePhone) {
        list.push({
          type: 'mobile',
          isVerify: opt.IsVerifyPhone, // 是否验证手机号
          data: [{
            type: 'phone',
            key: 'phone',
            value: '',
            label: '手机号',
            placeholder: '请输入手机号码',
            must: true,
            readonly: false,
            disabled: false,
            maxlength: 11
          }, {
            type: 'code',
            key: 'code',
            value: '',
            label: '验证码',
            placeholder: '请输入验证码',
            must: opt.IsVerifyPhone,
            readonly: false,
            disabled: false,
            maxlength: 30
          }]
        });
      }
      if (opt.IsShowEmail) {
        list.push({
          type: 'text',
          key: 'email',
          value: '',
          label: '邮箱',
          placeholder: '请输入邮箱',
          must: true,
          readonly: false,
          disabled: false,
          maxlength: 50
        });
      }
      if (opt.IsProvinceCity) {
        list.push({
          type: 'area',
          key: 'area',
          value: '',
          label: '省市区',
          placeholder: '请选择省市区',
          must: true,
          readonly: true, // 只读
          disabled: false,
          cols: 3, // 2-选择省市，3-选择省市区
          title: '选择省市区'
        });
      }
      if (opt.IsCompany) {
        list.push({
          type: 'text',
          key: 'company',
          value: '',
          label: '公司',
          placeholder: '请输入公司名称',
          must: true,
          readonly: false,
          disabled: false,
          maxlength: 50
        });
      }
      if (opt.IsPost) {
        list.push({
          type: 'text',
          key: 'post',
          value: '',
          label: '职务',
          placeholder: '请输入职务',
          must: true,
          readonly: false,
          disabled: false,
          maxlength: 30
        });
      }
      if (opt.IsShowTaxNumber) {
        list.push({
          type: 'text',
          key: 'TaxNumber',
          value: '',
          label: '税号',
          placeholder: '请输入税号',
          must: true,
          readonly: false,
          disabled: false,
          maxlength: 30
        });
      }
      if (opt.IsCompany) {
        list.push({
          type: 'textarea',
          key: 'introduce',
          value: '',
          label: '公司简介',
          placeholder: '请输入公司简介',
          must: true,
          readonly: false,
          disabled: false,
          maxlength: 150 // 最大长度
        });
      }
      if (opt.IsShowQuestionnaire) {
        list.push({
          type: 'questionnaire',
          data: opt.QuestionnaireItems
        });
      }
      if (opt.IsChannel) {
        let arry = opt.Channel.split(',');
        var lists = [];
        arry.forEach(item => {
          lists.push({
            text: item,
            value: item
          });
        });
        list.push({
          type: 'picker',
          key: 'channel',
          value: '',
          label: '渠道',
          placeholder: '请选择渠道',
          must: true,
          readonly: true,
          disabled: false,
          data: list // 选择项数据列表，text、value
        });
      }
      if (opt.IsWish) {
        list.push({
          type: 'textarea',
          key: 'wish',
          value: '',
          label: '祝福语',
          placeholder: '请输入祝福语',
          must: false,
          readonly: false,
          disabled: false,
          maxlength: 150 // 最大长度
        });
      }
      return list;
    };
  }
};
